define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'gonghuo/index' + location.search,
                    add_url: 'gonghuo/add',
                    edit_url: 'gonghuo/edit',
                    del_url: 'gonghuo/del',
                    multi_url: 'gonghuo/multi',
                    table: 'gonghuo',

                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'nickname', title: __('User_id')},
                        {
                            field: 'good_json',operate:false, title: '商品名称',formatter:function(value,row,index){
                               
                               
                                var goods_name = '';
                                for (var i = row.good_json_text.length - 1; i >= 0; i--) {
                                    goods_name += row.good_json_text[i]['name']+'<br><br>';
                                }
                                return goods_name;

                            }
                        },
                                                {
                            field: 'good_json',operate:false, title: '条形码',formatter:function(value,row,index){
                               
                               
                                var codebar = '';
                                for (var i = row.good_json_text.length - 1; i >= 0; i--) {
                                    codebar += row.good_json_text[i]['codebar']+'<br><br>';
                                }
                                return codebar;

                            }
                        },
                        {
                            field: 'good_json',operate:false, title: '批号',formatter:function(value,row,index){
                               
                               
                                var pihao = '';
                                for (var i = row.good_json_text.length - 1; i >= 0; i--) {
                                    pihao += row.good_json_text[i]['pihao']+'<br><br>';
                                }
                                return pihao;

                            }
                        },
                        {
                            field: 'good_json',operate:false, title: '货号',formatter:function(value,row,index){
                               
                               
                                var huohao = '';
                                for (var i = row.good_json_text.length - 1; i >= 0; i--) {
                                    huohao += row.good_json_text[i]['huohao']+'<br><br>';
                                }
                                return huohao;

                            }
                        },
                        
                        {
                            field: 'good_json',operate:false, title: '免税编号',formatter:function(value,row,index){
                               
                               
                                var mianshui = '';
                                for (var i = row.good_json_text.length - 1; i >= 0; i--) {
                                    mianshui += row.good_json_text[i]['mianshui']+'<br><br>';
                                }
                                return mianshui;

                            }
                        },
                        {
                            field: 'good_json',operate:false, title: '单价',formatter:function(value,row,index){
                               
                               
                                var unit_price = '';
                                for (var i = row.good_json_text.length - 1; i >= 0; i--) {
                                    unit_price += row.good_json_text[i]['unit_price']+'<br><br>';
                                }
                                return unit_price;

                            }
                        },
                        {
                            field: 'good_json',operate:false, title: '折扣',formatter:function(value,row,index){
                               
                               
                                var zhekou = '';
                                for (var i = row.good_json_text.length - 1; i >= 0; i--) {
                                    zhekou += row.good_json_text[i]['zhekou']+'<br><br>';
                                }
                                return zhekou;

                            }
                        },
                        {
                            field: 'good_json',operate:false, title: '折后单价',formatter:function(value,row,index){
                               
                               
                                var after_unit_price = '';
                                for (var i = row.good_json_text.length - 1; i >= 0; i--) {
                                    after_unit_price += row.good_json_text[i]['after_unit_price']+'<br><br>';
                                }
                                return after_unit_price;

                            }
                        },
                        {
                            field: 'good_json',operate:false, title: '原总价',formatter:function(value,row,index){
                               
                               
                                var origin_total_price = '';
                                for (var i = row.good_json_text.length - 1; i >= 0; i--) {
                                    origin_total_price += row.good_json_text[i]['origin_total_price']+'<br><br>';
                                }
                                return origin_total_price;

                            }
                        },
                        {
                            field: 'good_json',operate:false, title: '折后总价',formatter:function(value,row,index){
                               
                               
                                var after_total_price = '';
                                for (var i = row.good_json_text.length - 1; i >= 0; i--) {
                                    after_total_price += row.good_json_text[i]['after_total_price']+'<br><br>';
                                }
                                return after_total_price;

                            }
                        },
                        {
                            field: 'good_json',operate:false, title: '订货数量',formatter:function(value,row,index){
                               
                               
                                var ding_num = '';
                                for (var i = row.good_json_text.length - 1; i >= 0; i--) {
                                    ding_num += row.good_json_text[i]['ding_num']+'<br><br>';
                                }
                                return ding_num;

                            }
                        },
                        {
                            field: 'good_json',operate:false, title: '已发货数量',formatter:function(value,row,index){
                               
                               
                                var yifahuo = '';
                                for (var i = row.good_json_text.length - 1; i >= 0; i--) {
                                    yifahuo += row.good_json_text[i]['yifahuo']+'<br><br>';
                                }
                                return yifahuo;

                            }
                        },
                        {
                            field: 'good_json',operate:false, title: '未发货数量',formatter:function(value,row,index){
                               
                               
                                var weifahuo = '';
                                for (var i = row.good_json_text.length - 1; i >= 0; i--) {
                                    weifahuo += row.good_json_text[i]['weifahuo']+'<br><br>';
                                }
                                return weifahuo;

                            }
                        },
                        {
                            field: 'good_json',operate:false, title: '本次发货数量',formatter:function(value,row,index){
                               
                               
                                var now_fahuo_num = '';
                                for (var i = row.good_json_text.length - 1; i >= 0; i--) {
                                    now_fahuo_num += row.good_json_text[i]['now_fahuo_num']+'<br><br>';
                                }
                                return now_fahuo_num;

                            }
                        },
                       
                        {field: 'gongtime', title: __('Gongtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});